#!/bin/bash

# https://blog.csdn.net/qqqq0199181/article/details/81738294

set -e

source common.sh

t_simple() {
    f=testdata/grade.txt
    echo_red "deleting Lulu and two lines below it"
    sed '/Lulu/, +2d' $f  # 包括Lulu 和下面2行 , 不可以把 , 写成 空格
    
    # 删掉 Lulu 行 和 第4行中间的所有行
    echo_blue "\ndeleting all lines between Lulu and 4th line. This is a rare use case"
    sed '/Lulu/, 4d' $f

    # https://stackoverflow.com/questions/4396974/sed-or-awk-delete-n-lines-following-a-pattern
    # 删除Lulu 下的两行，不包括 Lulu 行
    # 如果第一个 n 写成 N ，则包括 Lulu 行
    echo_red "\ndeleting two lines below Lulu line, excluding Lulu line. This is a very strange grammar"
    sed '/Lulu/{n;N;d;}' $f

    # https://stackoverflow.com/questions/13316437/insert-lines-in-a-file-starting-from-a-specific-line
    # 在匹配行上下插入行
    echo_blue "\ninsert line after matching line"
    sed -e '2 a line 2.5' $f
    echo_blue "\ninsert line before matching line"
    sed -e '2 i line 1.2' $f
}

t_simple